﻿// 功能：弹出表格式菜单项集合
// 描述：
// 作者：温伟鹏
// 日期：2010/5/13 17:10:07

using System;
using System.Collections.Generic;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 弹出表格式菜单项集合
    /// </summary>
    public class GridMenuItemCollection
    {
        #region 私有变量
        private GridMenu owner;
        private Dictionary<int, GridMenuItem> items;
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取集合的所有者
        /// </summary>
        public GridMenu Owner
        {
            get
            {
                return owner;
            }
        }
        /// <summary>
        /// 获取集合中的菜单项数量
        /// </summary>
        public int Count
        {
            get
            {
                return items.Count;
            }
        }
        /// <summary>
        /// 获取集合中指定索引的菜单项
        /// </summary>
        /// <param name="index">菜单项在集合中的索引值</param>
        /// <returns></returns>
        public GridMenuItem this[int index]
        {
            get
            {
                if (items.ContainsKey(index))
                    return items[index];
                return null;
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造弹出表格菜单项集合
        /// </summary>
        /// <param name="owner">菜单项集合所有者</param>
        public GridMenuItemCollection(GridMenu owner)
        {
            this.owner = owner;
            this.items = new Dictionary<int, GridMenuItem>();
        }
        #endregion

        #region 函数
        /// <summary>
        /// 向集合中添加菜单项
        /// </summary>
        /// <param name="item">菜单项</param>
        public void Add(GridMenuItem item)
        {
            Owner.AppendMenuItem(item.ItemId, item.Text, item.ItemImage, item.ItemImagePressed);
            item.Owner = Owner;
            items.Add(item.ItemId, item);
        }
        /// <summary>
        /// 清空所有菜单项
        /// </summary>
        public void Clear()
        {
            this.items.Clear();
            this.Owner.RemoveAllItems();
        }
        #endregion
    }
}
